package db;

import java.sql.*;

import oracle.*;
import oracle.jdbc.*;

import java.util.*;

import sun.jdbc.odbc.*;

public class DB_Access
{
	public static Connection getConnection ()
	{
		Connection connection = null;
		try
		{
			// Load the JDBC driver
			String driverName = "oracle.jdbc.OracleDriver";
			Class.forName(driverName);
			// Create a connection to the database
			String serverName = "127.0.0.1";
			String portNumber = "1521";
			String sid = "xe";
			String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber
					+ ":" + sid;
			System.out.println(url);
			String username = "michael";
			String password = "a02041990";
			try
			{
				connection = DriverManager.getConnection(url, username, password);
			}
			catch (Exception e)
			{
				System.out.println("Connection Error: " + e);
			}
			
		}
		catch (ClassNotFoundException e)
		{
			System.out.println("Error Class Not Found" + e);
		}
		return connection;
	}
	
	public static ArrayList<String> getUsernames () throws Exception
	{
		ArrayList<String> arr_Usernames = new ArrayList<String>();
		
		Connection con = getConnection();
		Statement stmt = con.createStatement();
		ResultSet rs = stmt.executeQuery("SELECT username FROM t_user");
		
		while(rs.next())
		{
			arr_Usernames.add(rs.getString("username"));
		}
		
		con.close();
		
		return arr_Usernames;
	}
}
	
	
